home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 83win / data1.cab / DLL_Toolkit / Source / HTBSwitch / SwitchDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-02  |  5.0 KB  |  200 lines

  1. /*****************************************************
  2. HTBSwitch.dll
  3.  
  4. SwitchDlg.cpp
  5.  
  6. Copyright 1999 TransEra Corporation
  7. *****************************************************/
  8.  
  9. #include "stdafx.h"
  10. #include "HTBswitch.h"
  11. #include "SwitchDlg.h"
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. #define START_SIZE_X        110
  20. #define START_SIZE_Y        200
  21. #define TIMERVAL            100
  22. #define GREY_COLOR            190
  23. #define DARK_GREY            125
  24. #define OUT_TXT_POS            115
  25. #define TOP_X                30
  26. #define TOP_Y                10
  27. #define BOTTOM_X            70
  28. #define BOTTOM_Y            30
  29. #define MEDIAN                40
  30. #define COLOR_MAX            255
  31. #define COLOR_MIN            0
  32. #define BOTTOM_SWITCH_POS    100
  33. #define TOP_SWITCH_POS        70
  34. #define BOTTOM_TXT_POS        37
  35. #define OFF_SWITCH            "OFF"
  36. #define ON_SWITCH            "ON"
  37.  
  38. short sem = 0;
  39. int iOutlineX1 = TOP_X;
  40. int iOutlineY1 = BOTTOM_X;
  41. int iOutlineX2 = BOTTOM_X;
  42. int iOutlineY2 = BOTTOM_SWITCH_POS;
  43. int iColor1  = COLOR_MAX;
  44. int iColor2  = COLOR_MIN;
  45. int TboxXPos = BOTTOM_TXT_POS;
  46. CString Out_Text = OFF_SWITCH;
  47.  
  48. SwitchDlg::SwitchDlg(CWnd* pParent /*=NULL*/)
  49.     : CDialog(SwitchDlg::IDD, pParent) 
  50. {
  51.     //{{AFX_DATA_INIT(SwitchDlg)
  52.         // NOTE: the ClassWizard will add member initialization here
  53.     //}}AFX_DATA_INIT
  54. }
  55.  
  56. void SwitchDlg::DoDataExchange(CDataExchange* pDX) 
  57. {
  58.     CDialog::DoDataExchange(pDX);
  59.     //{{AFX_DATA_MAP(SwitchDlg)
  60.         // NOTE: the ClassWizard will add DDX and DDV calls here
  61.     //}}AFX_DATA_MAP
  62. }
  63.  
  64. BEGIN_MESSAGE_MAP(SwitchDlg, CDialog)
  65.     //{{AFX_MSG_MAP(SwitchDlg)
  66.     ON_WM_PAINT()
  67.     ON_WM_TIMER()
  68.     ON_WM_LBUTTONDOWN()
  69.     //}}AFX_MSG_MAP
  70. END_MESSAGE_MAP()
  71.  
  72.  
  73. /////////////////////////////////////////////////////////////////////////////
  74. /*
  75.     Function:        SwitchDlg::OnInitDialog
  76.  
  77.     Description:    Initializes app.
  78.  
  79.     Return type:    BOOL 
  80.  
  81.     Notes:            This function takes the input from the user and    
  82.                     starts the dialog box window in the appropriate
  83.                     X & Y locations specified, along with other 
  84.                     dialof box properties.  This function also calls
  85.                     the timer.
  86.         
  87. */
  88. BOOL SwitchDlg::OnInitDialog()  
  89. {
  90.     CDialog::OnInitDialog();    
  91.     SetWindowPos(FromHandle(m_hWnd), g_Xpos, g_Ypos, START_SIZE_X, 
  92.                 START_SIZE_Y, SWP_NOZORDER);
  93.     SetTimer(1,TIMERVAL,NULL);    
  94.     return TRUE;  
  95. }
  96.  
  97.  
  98. /////////////////////////////////////////////////////////////////////////////
  99. /*
  100.     Function:        SwitchDlg::OnPaint
  101.  
  102.     Description:    Paints the data onto the dialog box window
  103.  
  104.     Return type:    void 
  105.  
  106.     Notes:            Paints the colors, lines and shapes onto the dialog
  107.                     box window from the dc calls.  
  108.         
  109. */
  110. void SwitchDlg::OnPaint()  
  111. {
  112.     CPaintDC dc(this); 
  113.     CBrush lightcolor(RGB(iColor1,iColor2,0));    
  114.     CBrush  grey(RGB(GREY_COLOR,GREY_COLOR,GREY_COLOR));
  115.     CBrush  dark(RGB(DARK_GREY,DARK_GREY,DARK_GREY));
  116.     dc.SelectObject(&lightcolor);
  117.     dc.Rectangle(TOP_X,TOP_Y,BOTTOM_X,BOTTOM_Y);
  118.     dc.SelectObject(&grey);
  119.     dc.Rectangle(TOP_X,(TOP_Y + BOTTOM_SWITCH_POS),BOTTOM_X,(MEDIAN + BOTTOM_SWITCH_POS));
  120.     dc.Rectangle(TOP_X,MEDIAN,BOTTOM_X,BOTTOM_SWITCH_POS);
  121.     dc.SelectObject(&dark);
  122.     dc.Rectangle(iOutlineX1,iOutlineY1,iOutlineX2,iOutlineY2);
  123.     dc.TextOut(TboxXPos,OUT_TXT_POS,Out_Text);
  124. }
  125.  
  126.  
  127. /////////////////////////////////////////////////////////////////////////////
  128. /*
  129.     Function:        SwitchDlg::OnTimer
  130.  
  131.     Description:    Timer function call
  132.  
  133.     Return type:    void 
  134.     Argument:        UINT nIDEvent
  135.  
  136.     Notes:            this function updates the graphical data on the dialog box
  137.                     by invalidating it on every timer strobe.
  138.         
  139. */
  140. void SwitchDlg::OnTimer(UINT nIDEvent)  
  141. {    
  142.     Invalidate();
  143.     CDialog::OnTimer(nIDEvent);
  144. }
  145.  
  146.  
  147. /////////////////////////////////////////////////////////////////////////////
  148. /*
  149.     Function:        SwitchDlg::OnLButtonDown
  150.  
  151.     Description:    takes input from left mouse button
  152.  
  153.     Return type:    void 
  154.     Argument:        UINT nFlags
  155.     Argument:        CPoint point
  156.  
  157.     Notes:            takes input from mouse and decides whether or not
  158.                     that input needs to make the value and color of the 
  159.                     switch change if it does need to change, this function 
  160.                     will do so.
  161.         
  162. */
  163. void SwitchDlg::OnLButtonDown(UINT nFlags, CPoint point)  
  164. {
  165.  
  166.     int x = 0;                    // X position of left-Mouse click
  167.     int y = 0;                    // Y position of left-Mouse click
  168.     CPoint m_Point;
  169.     
  170.     m_Point = point;
  171.     x = m_Point.x;
  172.     y = m_Point.y;
  173.  
  174.     // Color and Position of the switch
  175.     if (x > BOTTOM_Y && x < BOTTOM_X && y > MEDIAN && y < BOTTOM_X) { //ON
  176.         iColor1 = COLOR_MIN;
  177.         iColor2 = COLOR_MAX;
  178.         iOutlineX1 = BOTTOM_Y;
  179.         iOutlineY1 = MEDIAN;
  180.         iOutlineX2 = TOP_SWITCH_POS;
  181.         iOutlineY2 = TOP_SWITCH_POS;
  182.         TboxXPos = MEDIAN;
  183.         Out_Text = ON_SWITCH;
  184.         * RetVal = 1;
  185.     }
  186.     // Color and Position of the switch
  187.     if (x > BOTTOM_Y && x < BOTTOM_X && y > BOTTOM_X && y < BOTTOM_SWITCH_POS) { //OFF
  188.         iColor1 = COLOR_MAX;
  189.         iColor2 = COLOR_MIN;
  190.         iOutlineX1 = BOTTOM_Y;
  191.         iOutlineY1 = TOP_SWITCH_POS;
  192.         iOutlineX2 = TOP_SWITCH_POS;
  193.         iOutlineY2 = BOTTOM_SWITCH_POS;
  194.         TboxXPos = BOTTOM_TXT_POS;
  195.         Out_Text = OFF_SWITCH;
  196.         * RetVal = 0;
  197.     }
  198.     CDialog::OnLButtonDown(nFlags, point);
  199. }
  200.